﻿using System;

namespace Program25
{
    class Program
    {
        static void Main(string[] args)
        {
            //GetSum(1,4,7...)求任意长度的和
            //Console.WriteLine(GetSum(8,9));
            //Console.WriteLine(GetSum(8,9,10,11));

            //Test("小明","100级",100,98);
            //GetScore("张三",学号，成绩1，成绩2，...)求任意门课程的总分
            GetScore("张三", 2468, 98, 100, 70);
        }
        //params定义可变参数
        public static int GetSum(params int[] n)
        {
            var sum = 0;
            for (var i = 0; i < n.Length; i++)
            {
                sum += n[i];
            }
            return sum;
        }
        public static void Test(params Object[] objs)
        {
            Console.WriteLine(objs[0]);
            Console.WriteLine(objs[1]);
            Console.WriteLine(objs[2]);
            Console.WriteLine(objs[3]);
        }
        //可变参数放在所有形参的末尾
        public static void GetScore(string name, int id, params int[] scores)
        {
            Console.WriteLine("学号：" + id);
            Console.WriteLine("姓名：" + name);
            var sum = 0;
            for (var i = 0; i < scores.Length; i++)
            {
                sum += scores[i];
            }
            Console.WriteLine("总分：" + sum);
            Console.WriteLine("平均分：" + sum / scores.Length);
        }
    }
}
